/*
 * BinaryTree.java
 *
 * Created on July 4, 2006, 1:13 PM
 *
 */

package galronnlp.util;

import galronnlp.pcfg.grammar.Rule;
import galronnlp.pcfg.grammar.BinaryRule;
import java.util.Iterator;
import java.util.LinkedList;

/**
 *
 * @author Daniel A. Galron
 */
public class BinaryTree extends Tree{
    private boolean displayProbs = true;
    private TreeStringGenerator stringGen = new PennTreebankStringTreeGenerator(displayProbs);
       
    /** Creates a new instance of BinaryTree */
    public BinaryTree(Symbol cat, Tree lRHS, Tree rRHS, double prob) {
        this.type = BINARY;
        this.category = cat;
        this.probability = prob;
        lRHS.setParent(this);
        rRHS.setParent(this);
        this.children.addLast(lRHS);
        this.children.addLast(rRHS);
    }
    
    public BinaryTree(Symbol cat, Tree lRHS, Tree rRHS) {
        this(cat, lRHS, rRHS, 0.0);
    }

    public LinkedList<Symbol> RHS() {
        LinkedList<Symbol> RHS = new LinkedList<Symbol>();
        for(Iterator<Tree> it = this.children.iterator(); it.hasNext(); ) {
            RHS.addLast(it.next().cat());
        }
        return RHS;
    }

    public boolean equals(Object o) {
        Tree other = (Tree)o;
        boolean ret = false;
        if(other.type() == BINARY) {
            ret = ((Tree)this.children.get(0)).equals((Tree)other.children.get(0)) &&
                  ((Tree)this.children.get(1)).equals((Tree)other.children.get(1)) &&
                  this.category.equals(other.category);
        }
        return ret;
    }

 /*   public void addToGrammar(Grammar g) {
        ((Tree)children.get(0)).addToGrammar(g);
        ((Tree)children.get(1)).addToGrammar(g);
        Rule r = new BinaryRule(this.cat(), this.children, this.prob());
        g.
    }*/
}
